/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package respaldomysql;

import java.util.Vector;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;

/**
 *
 * @author Lolo
 */
public class jDataTable extends JTable{
    
    private Vector columns;

    public Vector getColumns() {
        return columns;
    }

    public void setColumns(Vector columns) {
        this.columns = columns;
    }
    
    private Vector<Vector> rows;

    public Vector<Vector> getRows() {
        return rows;
    }

    public void setRows(Vector<Vector> rows) {
        this.rows = rows;
    }
    
    public jDataTable(){
        rows = new Vector<Vector>();
        columns = new Vector();
        actualizarDataModel();
    }

    public void addColumn(String nombreColumna){        
        columns.add(nombreColumna);
        actualizarDataModel();
    }

    public void addRow(Vector row){
        rows.add(row);
        actualizarDataModel();
    }

    
    public void addRow(Object[] row){
        Vector vRow = new Vector();
        for (int i = 0; i < row.length; i++) {
            vRow.add(row[i]);
        }
        rows.add(vRow);
        actualizarDataModel();
    }
    
    public Vector getRow(int index){
        return rows.get(index);
    }

    public Object getRowCell(int index,String nombreColumna){
        return rows.get(index).get(columns.indexOf(nombreColumna));
    }
    
    public void removeRow(int index){
        rows.removeElementAt(index);
        actualizarDataModel();
    }
     
    public void removeRow(String nombreColumna){
        rows.removeElementAt(columns.indexOf(nombreColumna));
        actualizarDataModel();
    }
    
    private void actualizarDataModel() {
        this.setModel(new DefaultTableModel(rows,columns));
        
//        for (int i = 0; i < this.rows.size(); i++) {
//            for (int j = 0; j < this.columns.size(); j++) {
//                
//            }
//        }
    }
}